<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true">
      <el-form-item label="班级" prop="classId">
        <el-select
          v-model="queryParams.classId"
          placeholder="请选择班级"
          clearable
          size="small"
          style="width: 240px"
        >
          <el-option
            v-for="item in classOption"
            :key="item.id"
            :label="item.className"
            :value="item.id"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table :data="dataList" v-loading="loading">
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column
        type="index"
        :index="table_index"
        label="序号"
        align="center"
      />
      <el-table-column prop="id" align="center" label="id" v-if="false" />
      <el-table-column prop="studentId" align="center" label="学号" />
      <el-table-column prop="name" align="center" label="姓名" />
      <el-table-column prop="gender" align="center" label="性别">
        <template slot-scope="scope">
          {{ scope.row.gender == 0 ? "男" : "女" }}
        </template>
      </el-table-column>
      <el-table-column prop="classId" align="center" label="班级">
        <template slot-scope="scope">
          {{ getLable(classOption, scope.row.classId, "id", "className") }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <el-button
            size="mini"
            circle
            type="success"
            icon="el-icon-edit"
            @click="handleEnter(scope.row)"
          />
          <el-button
            size="mini"
            circle
            type="info"
            icon="el-icon-search"
            @click="handleView(scope.row)"
          />
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <el-dialog
      :title="title"
      :visible.sync="enterDialogVisible"
      width="50%"
      :before-close="handleClose"
    >
      <el-form :model="behaviorDataFrom" ref="behaviorDataFrom">
        <el-form-item label="评分标题" prop="behaviorTitle">
          <el-select
            v-model="behaviorDataFrom.behaviorTitle"
            placeholder="请选择"
            clearable
            size="small"
            style="width: 240px"
            @change="getCfgItems()"
          >
            <el-option
              v-for="item in cfgOption"
              :key="item.id"
              :label="item.behaviorTitle"
              :value="item.id"
            />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-table
            :data="behaviorDataFrom.markItemList"
            border
            style="width: 100%"
          >
          <template v-for="(col,index) in markItems">
            <el-table-column
            :key="index"
              :prop="col.prop"
              :label="col.markItem"
            >

            </el-table-column>
          </template>
          </el-table>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { findClassByTeacher } from "@/api/classManage/classInfo";
import { findStudentInfoByClass } from "@/api/studentInfo/infoMaintenance/index";
import { findCfgByClassId } from "@/api/studyManage/behaviorCfgClass";
import { findBehaviorCfgItemByCfgId } from "@/api/studyManage/behaviorCfgItem";

export default {
  name: "BehaviorEntry",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      //数据列表
      dataList: [],
      //班级选项
      classOption: [],
      //配置选项
      cfgOption: [],
      markItems:[],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        classId: undefined,
      },
      enterDialogVisible: false,
      behaviorDataFrom: {
        id:undefined,
        behaviorTitle: undefined,
        markItemList: [],
      },
      isView: false,
      rules: {},
    };
  },
  computed: {},

  created() {
    this.getList();
    this.getClassByTeacher();
  },

  methods: {
    /** 分页序号自增 */
    table_index(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    /** 根据老师查询班级 */
    getClassByTeacher() {
      findClassByTeacher().then((result) => {
        this.classOption = result.data;
      });
    },

    /** 查询参数列表 */
    getList() {
      this.loading = false;
      findStudentInfoByClass(this.queryParams)
        .then((resp) => {
          console.log(resp);
          this.dataList = resp.data.list;
          this.total = resp.data.total;
          this.loading = false;
        })
        .catch((res) => {
          this.loading = false;
        });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    /** 重置查询 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },

    /** 多选 */
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },

    /** 录入分数 */
    handleEnter(row) {
      this.enterDialogVisible = true;
      findCfgByClassId(row.classId).then((resp) => {
        this.cfgOption = resp.data;
      });
      // this.title = row.name + row.
    },

    getCfgItems(cfgId){
      console.log(cfgId);
      findBehaviorCfgItemByCfgId().then((resp) => {
        this.markItems = resp.data;
      })
    },

    /** 关闭弹窗 */
    handleClose(done) {
      this.enterDialogVisible = false;
    },

    // handleView(row) {
    //   this.dialogVisible = true;
    // },

    /** 重置表单 */
    reset() {
      // this.behaviorCfgForm = {
      //   id: undefined,
      //   cfgTitle: undefined,
      //   classId: undefined,
      //   scoreCycle: undefined,
      //   behaviorCfgItemList: [{ itemName: undefined }],
      // };
      // this.resetForm("behaviorCfgForm");
    },

    submitForm() {
      // console.log(this.behaviorCfgForm);
      // this.$refs["behaviorCfgForm"].validate((valid) => {
      //   if (valid) {
      //     addOrUpdateBehaviorCfg(this.behaviorCfgForm).then((resp) => {
      //       this.$message({ message: "提交成功", type: "success" });
      //       this.dialogVisible = false;
      //       this.getList();
      //     });
      //   }
      // });
    },
  },
};
</script>

<style>
</style>